<template>
  <el-form>
    <el-row>
      <el-col :span="6">
        <el-form-item label="姓名">
          <el-input v-model.trim="user.name" />
        </el-form-item>
      </el-col>
    </el-row>
    <el-row>
      <el-col :span="6">
        <el-form-item label="邮箱">
          <el-input v-model.trim="user.email" />
        </el-form-item>
      </el-col>
    </el-row>
    <el-form-item>
      <el-button type="primary" @click="submit">更新</el-button>
    </el-form-item>
  </el-form>
</template>

<script>

export default {
  props: {
    user: {
      type: Object,
      default: () => {
        return {
          name: '',
          email: ''
        }
      }
    }
  },
  methods: {
    async submit() {
      await this.$store.dispatch('user/updateProfile',
        {
          email: this.user.email,
          name: this.user.name,
          userName: this.user.name
        })

      this.$message({
        message: '个人资料更新成功',
        type: 'success',
        duration: 5 * 1000
      })
    }
  }
}
</script>
